package ml;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

public class UpAndCountDownLatch extends CountDownLatch {

	private final AtomicInteger count = new AtomicInteger(0);

	public UpAndCountDownLatch() {
		super(1);
	}

	public void countUp() {
		count.incrementAndGet();
	}

	@Override
	public void countDown() {
		if (count.decrementAndGet() == 0) {
			super.countDown();
		}
	}
}
